/**
 * @作者 faner
 * @创建时间 2021/1/11 14:32
 */
package com.faner.fast.upms.excel;

import com.faner.fast.excel.annotation.ExcelListener;
import com.faner.fast.excel.event.AnalysisEventAutoListener;
import com.faner.fast.excel.kit.ExcelResult;
import com.faner.fast.upms.domain.bo.FileExcelBO;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.function.Function;

@ExcelListener("FileEventListener")
public class FileEventListener extends AnalysisEventAutoListener<FileExcelBO> {
    public FileEventListener() {
        super(1000);
    }

    @Override
    public Class<FileExcelBO> getClazz() {
        return FileExcelBO.class;
    }

    @Override
    public ExcelResult<FileExcelBO> checkData(List<FileExcelBO> dataList) {
        List<FileExcelBO> successList = Lists.newArrayList();
        List<FileExcelBO> errorList = Lists.newArrayList();

        String errMsg;
        for (FileExcelBO fileExcelBO : dataList) {
            errMsg = "";

            if (StringUtils.isBlank(errMsg)) {
                successList.add(fileExcelBO);
            } else {
                fileExcelBO.setValidateMessage(errMsg);
                errorList.add(fileExcelBO);
            }
        }

        return new ExcelResult<>(successList, errorList);
    }

    @Override
    protected Function<List<FileExcelBO>, Object> storageDataFun() {

        return (fileExcelBOS) -> {
            List<FileExcelBO> fileExcelBOList = Lists.newArrayList();
            fileExcelBOS.forEach(f ->  {
                System.out.println(f);
            });
            return "";
        };
    }
}
